module.exports = class extends baseLogic {
    constructor() {
        super();

    }

    /**
     * 获取站点模块列表
     * @returns {Promise<Array<Model>>}
     */
    async getItems() {
        let ret = await this.DB.cms_site_module.Access.findAll({
            order: [
                ['sm_isSys', 'desc'],
                ['sm_name', 'desc']
            ],
            raw: true
        });
        return ret;
    }

    async getItem(id) {
        let model = await this.DB.cms_site_module.Access.findOne({
            where: {
                sm_id: id
            },
            raw: true
        });
        return model;
    }

    async edit(_model) {
        let model = {};
        if (_model.sm_id && _model.sm_id !== '') {
            model = await this.getItem(_model.sm_id);
            if (!model) {
                return false;
            }
        } else {
            model.sm_id = this.webTools.myuuid.createUUID();
            model.sm_createTime = this.moment().format("YYYY-MM-DD HH:mm:ss");
            model.sm_isSys = 0;
            model.realViewPath = _model.sm_viewPath;
        }
        model.sm_name = _model.sm_name;
        model.sm_viewPath = _model.sm_viewPath;
        model.sm_remark = _model.sm_remark;
        model.sm_url = _model.sm_url;
        model.sm_pageTitle = _model.sm_pageTitle;
        model.sm_keyWord = _model.sm_keyWord;
        if (_model.sm_id && _model.sm_id !== '') {
            model = await this.DB.cms_site_module.Access.update(model, {
                where: {
                    sm_id: _model.sm_id
                }
            })
        } else {
            model = await this.DB.cms_site_module.Access.create(model);
        }

        if (model) {
            return true;
        }
        return false;
    }

    async del(id) {
        let ret = await this.DB.cms_site_module.Access.destroy({
            where: {
                sm_id: id
            }
        });
        return ret;
    }


};